home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / xvisrc.zip / ASCII.H < prev    next >
C/C++ Source or Header  |  1992-07-28  |  3KB  |  119 lines

  1. /* Copyright (c) 1990,1991,1992 Chris and John Downey */
  2. /***
  3.  
  4. * @(#)ascii.h    2.1 (Chris & John Downey) 7/29/92
  5.  
  6. * program name:
  7.     xvi
  8. * function:
  9.     PD version of UNIX "vi" editor, with extensions.
  10. * module name:
  11.     ascii.h
  12. * module function:
  13.     Keycode definitions for special keys - e.g. help, cursor arrow
  14.     keys, page up, page down etc., & test & conversion macros for
  15.     single characters.
  16.  
  17.     On systems that have any special keys, the routine 'inchar' in
  18.     the terminal interface code should return one of the codes
  19.     here.
  20.  
  21.     This file is specific to the ASCII character set; versions for
  22.     other character sets could be implemented if required.
  23. * history:
  24.     STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  25.     Originally by Tim Thompson (twitch!tjt)
  26.     Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  27.     Heavily modified by Chris & John Downey
  28.  
  29. ***/
  30.  
  31. #include <ctype.h>
  32.  
  33. /*
  34.  * Tests on single characters.
  35.  */
  36. #define is_alpha(c)    (isascii(c) && isalpha(c))
  37. #define is_upper(c)    (isascii(c) && isupper(c))
  38. #define is_lower(c)    (isascii(c) && islower(c))
  39. #define is_digit(c)    (isascii(c) && isdigit(c))
  40. #define is_xdigit(c)    (isascii(c) && isxdigit(c))
  41. #define is_octdigit(c)    ((c) >= '0' && (c) <= '7')
  42. #define is_space(c)    (isascii(c) && isspace(c))
  43. #define is_punct(c)    (isascii(c) && ispunct(c))
  44. #define is_alnum(c)    (isascii(c) && isalnum(c))
  45. #define is_print(c)    (isascii(c) && isprint(c))
  46. #define is_graph(c)    (isascii(c) && isgraph(c))
  47. #define is_cntrl(c)    (isascii(c) && iscntrl(c))
  48.  
  49. /*
  50.  * Conversions.
  51.  *
  52.  * Note that no argument validity checking is performed.
  53.  */
  54. /*
  55.  * Upper case to lower case.
  56.  */
  57. #define to_lower(c)    ((c) | 040)
  58. /*
  59.  * Lower case to upper case.
  60.  */
  61. #define to_upper(c)    ((c) & 0137)
  62. /*
  63.  * Hexadecimal digit to binary integer.
  64.  */
  65. #define hex_to_bin(h)    (is_digit(h) ? (h) & 017 : ((h) & 7) + 9)
  66.  
  67. /*
  68.  * Key codes.
  69.  */
  70. #define K_HELP        0x80
  71. #define K_UNDO        0x81
  72. #define K_INSERT    0x82
  73. #define K_HOME        0x83
  74. #define K_UARROW    0x84
  75. #define K_DARROW    0x85
  76. #define K_LARROW    0x86
  77. #define K_RARROW    0x87
  78. #define K_CGRAVE    0x88    /* control grave accent */
  79. #define K_PGDOWN    0x89
  80. #define K_PGUP        0x8a
  81. #define K_END        0x8b
  82.  
  83. /*
  84.  * Function keys.
  85.  */
  86. #define K_FUNC(n)    (0xa0 + (n))
  87.  
  88. /*
  89.  * Some common control characters.
  90.  */
  91. #define ESC        '\033'
  92. #define DEL        '\177'
  93.  
  94. #undef    CTRL
  95. #define CTRL(x)     ((x) & 0x1f)
  96.  
  97. /*
  98.  * Convert a command character to an ASCII character.
  99.  *
  100.  * This is needed for normal(), which uses the mapped value as an
  101.  * index into a table.
  102.  *
  103.  * QNX is the only ASCII-based system which gives us a minor problem
  104.  * here because its newline character is the same as control-^; so we
  105.  * convert this value to an ASCII linefeed.
  106.  */
  107. #ifdef QNX
  108. #   define ascii_map(n)    ((n) == '\n' ? 012 : (n))
  109. #else
  110. #   define ascii_map(n)    (n)
  111. #endif
  112.  
  113. /*
  114.  * The top bit for extended character sets.
  115.  * Note that this is NOT related to the size of a char in bits,
  116.  * but to the ASCII character set - i.e. it is always 128.
  117.  */
  118. #define    TOP_BIT        128
  119.